//
//  UIFont+ItalicFont.m
//  CoolRollerSkating
//
//  Created by 谢伟康 on 15/11/12.
//  Copyright © 2015年 Coollang. All rights reserved.
//

#import "UIFont+ItalicFont.h"
#import "GlobalSetting.h"

@implementation UIFont (ItalicFont)

+(UIFont *)italicFontWithFontName:(NSString *)fontName fontSize:(CGFloat)fontSize italicDegree:(CGFloat)italicDegree
{
    CGAffineTransform matrix =  CGAffineTransformMake(1, 0, tanf(italicDegree * (CGFloat)M_PI / 180), 1, 0, 0);
    
    UIFontDescriptor *desc = [ UIFontDescriptor fontDescriptorWithName :fontName matrix :matrix];
    
    return [UIFont fontWithDescriptor :desc size :fontSize];
    
}

+(UIFont *)italicFontWithItalicDegree:(CGFloat)italicDegree font:(UIFont *)font
{
    CGAffineTransform matrix =  CGAffineTransformMake(1, 0, tanf(italicDegree * (CGFloat)M_PI / 180), 1, 0, 0);
    
    UIFontDescriptor *desc = [ UIFontDescriptor fontDescriptorWithName :font.fontName matrix :matrix];
    
    return [UIFont fontWithDescriptor :desc size :font.pointSize];
}

+ (UIFont *)systemFontOfSize_6:(CGFloat)size
{
    UIFont *font = nil;
    CGFloat scale = kSCREEN_WIDTH_RATIO;
    if (scale > 1.1 && scale < 1.2)
    {
        scale = 1.05;
    }
    else if (scale > 1.2)
    {
        scale = 1.1;
    }
    font = [UIFont systemFontOfSize:size*scale];
    
    return font;
}

+ (UIFont *)openSansFont:(OpenSansFont)type size:(float)size {
    NSString *fontName = @"OpenSans-Bold";
    switch (type) {
        case OpenSansBold:
            fontName = @"OpenSans-Bold";
            break;
        case OpenSansBoldItalic:
            fontName = @"OpenSans-BoldItalic";
            break;
        case OpenSansExtraBold:
            fontName = @"OpenSans-ExtraBold";
            break;
        case OpenSansExtraBoldItalic:
            fontName = @"OpenSans-ExtraBoldItalic";
            break;
        case OpenSansItalic:
            fontName = @"OpenSans-Italic";
            break;
        case OpenSansLight:
            fontName = @"OpenSans-Light";
            break;
        case OpenSansLightItalic:
            fontName = @"OpenSansLight-Italic";
            break;
        case OpenSansRegular:
            fontName = @"OpenSans";
            break;
        case OpenSansSemibold:
            fontName = @"OpenSans-Semibold";
            break;
        case OpenSansSemiboldItalic_0:
            fontName = @"OpenSans-SemiboldItalic";
            break;
        case HarabaraMaisBold:
            fontName = @"HarabaraMaisBold-HarabaraMaisBold";
            break;
    }

    //NSLog(@"%@",[UIFont fontNamesForFamilyName:@"Open Sans"]);
  
    // 对字体大小进行设配
    CGFloat scale = kSCREEN_WIDTH_RATIO;
    if (scale > 1.1 && scale < 1.2)
    {
        scale = 1.05;
    }
    else if (scale > 1.2)
    {
        scale = 1.1;
    }
    return [UIFont fontWithName:fontName size:size * scale];
}

@end
